﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Castle.Windsor;
using M2B.GestionEntretiens.Contracts;
using M2B.GestionEntretiens.Models;

namespace M2B.GestionEntretiens.Controllers
{
    public class HomeController : Controller
    {
        #region Properties

        public HomeModel HomeModel
        {
            get
            {

                var homeModel = Session["HomeModel"] as HomeModel;
                if (homeModel == null)
                {
                    var container = Session["Container"] as IWindsorContainer;
                    if (container != null) homeModel = new HomeModel(container.Resolve<ICandidatsService>());
                    Session["HomeModel"] = homeModel;
                }
                return homeModel;

            }
            private set { Session["HomeModel"] = value; }
        }
        #endregion

        public ActionResult Index()
        {


            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            var homeModel = Session["HomeModel"] as HomeModel;
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult Traitements()
        {
            return View(HomeModel.Traitements);
        }

        public ActionResult LancerTraitement(string codeTraitement)
        {
          return  RedirectToAction("Index", codeTraitement);
        }

    }
}
